<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Controllers;

use App\Format\GridFormat;
use App\Http\Requests\CreateGridRequest;
use App\Services\GridService;
use Illuminate\Http\Request;

class GridController extends Controller
{
    protected $gridService;

    public function __construct(GridService $gridService)
    {
        $this->gridService = $gridService;
    }

    public function getLists()
    {
        $res = $this->gridService->getGrids();
        return renderSuccessJson($res);
    }

    public function create(CreateGridRequest $createGridRequest)
    {
        $format = new GridFormat($createGridRequest->all());
        $this->gridService->create($format);
        return renderSuccessJson();
    }

    public function getAdminList(Request $request)
    {
        $res = $this->gridService->getAdminList();
        return renderSuccessJson($res);
    }

    public function update(Request $request)
    {
        $format = new GridFormat($request->all());
        $this->gridService->update($format);
        return renderSuccessJson();
    }

    public function delete(Request $request)
    {
        $id = $request->input('id');
        $this->gridService->delete($id);
        return renderSuccessJson();
    }
}
